<template>
  <!-- 海报 -->
  <div class="textposter" :class="widgetData.isShow==0?'flex':''">
    <template v-for="(item, index) in widgetData.value">
      <div class="image" :key="index" :id="item.siteId"
        :class="{'comBorder':comClass=='b'+index}"
        :style="{ width:`${widgetData.detail.width}px`, height:`${widgetData.detail.height}px`}"
        @click="handleClick($event,widgetData,item,'b'+index)">
        <!-- 热力图 -->
        <template v-for="(ele,idx) in mapData">
          <div v-if="ele.sitePageId == item.siteId" :key="idx+'a'" class="mark" 
            :style="{background:`#${ele.color}`,opacity:0.9}">
            <div>
              <div class="name">PV：{{ele.exposurePv}}</div>
              <div class="name">UV：{{ele.exposureUv}}</div>
            </div>
            <div class="level">Lv.{{ele.level}}</div>
          </div>
        </template>
        <!-- 组件 -->
        <template v-if="item.url!=''">
          <img :src="item.url">
          <div :id="'title'+index" class="title">{{item.name}}</div>
        </template>
        <template v-else>
          <div class="image">
            <i class="el-icon-picture"></i>
            <div class="title"><span>{{item.title}}</span></div>
          </div>
        </template>
        <i @click.stop="deleteItem($event,widgetData,item,index)" class="el-icon-error"></i>
      </div>
    </template>
  </div>
</template>

<script>
import { getSubStr } from '@/commont/utils/stringUtil.js'
export default {
  name: "textposter",
  props: {
    widgetData: {
      type: Object,
      required: true
    },
    comClass:{
      type: null,
      default: null
    },
    // 热力图
    mapData:{
      type: Array,
      default: () => []
    }
  },
  data () {
    return {}
  },
  computed: {},
  watch:{
    'widgetData.value':{
      handler(data){
        console.log(data);
        this.$nextTick(function() {
          data.forEach((item,idx) =>{
            document.getElementById('title'+idx).innerText = getSubStr(item.name,14,true);
          })
        })
      },
      deep: true,
    }
  },
  methods: {
    // 属性
    handleClick(e,items,item,idx){
      this.$emit('detailRecomm',e,items,item,idx)
    },
    // 删除
    deleteItem(e,items,item,index){
      this.$emit('deleteItem',e,items,item,index)
    },
  },
}
</script>

<style lang="less" scoped>
.textposter {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: row;
  .image{
    width: 100%;
    height: 100%;
    margin: 10px;
    position: relative;
    // 热力图
    .mark{
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      padding: 10px 15px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .name{
        color: #ffffff;
      }
      .level{
        color: #ffffff;
        text-align: right;
      }
    }
    .title{
      position: absolute;
      bottom: 0;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      width: 100%;
      height: 40px;
      line-height: 40px;
      font-size: 18px;
      padding: 13px;
      color: #fff;
      background: #000;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    &:hover{
      .el-icon-error{
        display: block;
      }
    }
    .el-icon-error{
      position: absolute;
      right: -10px;
      top: -6px;
      color: red;
      font-size: 25px;
      cursor: pointer;
      display: none;
      z-index: 9999;
    }
  }
  .comBorder{
    box-shadow: rgba(202,38,250,0.8) 0px 0px 10px 5px;
  }
  .el-icon-picture{
    width: 100%;
    height: 100%;
    font-size: 3.125rem;
    background: #ffffff;
    color: #c1c1c1;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  // 锚点定位
  .anchor{
    box-shadow: 1px 1px 10px 10px red;
  }
}
.flex{
  flex-flow: wrap;
  align-content: flex-start;
}
</style>